<template>
    <view class="container">
         <view class="bg-set"></view>
         <image src="../../static/images/table_bkg.jpg" class="img" />
         <view class="title">
             <view class="line"></view>
             <view class="txt">请选择对应日期预约点餐</view>
         </view>
       <view style="margin-top: 30rpx;"> 
        <!-- <navigator :url="'/pages/table_item/table_item?date=' + item.date + '&restaurantSerials=' + restaurantSerials" v-for="(item,index) in list" :key="index"> -->
       <navigator :url="Jump(item,index)" v-for="(item,index) in list" :key="index">
      
       
         <uni-card margin="10" padding="10px 0">
             <view class="content">
                 <view class="time">
                     <view>
                         <view style="font-size: 40rpx;margin-bottom: 10rpx;">{{item.m}}</view>
                         <view class="item">月<view style="font-size: 75rpx;margin: 0 10rpx;">{{item.d}}</view>{{item.txt}}</view>
                     </view>
                 </view>
                 <view style="color: black;">
                     <view style="font-weight: 700;">配送时间：</view>
                     <view>早餐：08：00之前送达</view>
                     <view>午餐：12：00之前送达</view>
                     <view>晚餐：18：00之前送达</view>
                     <view style="display: flex;align-items: center;" v-if="determine(item,index)">订餐截止：<uni-countdown @timeup="timeup" :show-day="false" :hour="hour(index)" :minute="minute(index)" :second="second(index)" backgroundColor="#007aff" color="#fff"/></view>
                     <view class="end" v-else>订餐时间已截止</view>
                 </view>
             </view>
         </uni-card>
      </navigator>
       </view>
         </view>
      
 </template>
 
 <script setup>
 import { onLoad ,onShow} from '@dcloudio/uni-app';
 import { useCartStore,useMemberStore} from '../../stores';
 import {GetDate,GetDateStr} from '../../utils/data'
 import {ref,watch} from 'vue'
 import { http } from '../../utils/http';
 const list=GetDate(2)//目前获取2天的数据
 const restaurantSerials=ref()
 const active=ref(0)
 const endTime=ref('')
 const userMember=useMemberStore()
 onLoad(async(e)=>{
    endTime.value=e.endTime
    const storeCart=useCartStore()
   restaurantSerials.value=e.restaurantSerials
   storeCart.cartObj.restaurantName=e.restaurantName
 })
 onShow(()=>{
    getCustomersInfo()
 })
 const hour=(index)=>{
	 const data = new Date()
	if(index == 0){
		return 0
	} else if(index == 1){
		
		const fanhui = 0
		if(data.getHours() <= 17){
			return 17 - data.getHours()
		} else {
			return 0
		}
	} else {
		const st = (17 -data.getHours() ) + 24
		return st
	}
 }
 const minute=(index)=>{
	const data = new Date()
	if(index == 0){
		return 0
	} else if(index == 1){
		const fanhui = 0
		if(data.getHours() <= 17){
			return 60 - data.getMinutes()
		} else {
			return 0
		}
	} else {
		return  60 - data.getMinutes()
	}
 }
 
 const second = (index)=>{
 	const data = new Date()
 	if(index == 0){
 		return 0
 	} else if(index == 1){
 		const fanhui = 0
 		if(data.getHours() <= 17){
 			return 60 - data.getSeconds()
 		} else {
 			return 0
 		}
 	} else {
 		return 60 - data.getSeconds()
 	}
 }
 const getCustomersInfo=async()=>{
    const res = await http({
    method: 'post',
    url: '/GetCustomersInfo',
    data: userMember.requestData
  })
 }
// const fn=(data,event)=>{
//     watch(data.toString(),(newVal,oldVal)=>{
//         console.log(newVal,'11111111111111111111111111111111111111');
//     })
// // uni.navigateBack({url:`/pages/table_item/table_item?date=${date}&restaurantSerials=${restaurantSerials.value}`})
// }

 //todo 获取当前时间日期距离指定时间日期还剩多久
//  const endTime=()=>{
//      const day=GetDateStr(0) // 当前系统时间
//      console.log(day,'9999999');
//      const dateTime=day.y+'/'+day.m+'/'+day.d+' '+'18:00:00' // 每天下午6点前
//      const endTime=new Date('2023/9/5 18:00:00')
//  const t = endTime.getTime()-day.getTime
//      let h = Math.floor(t / 1000 / 60 / 60 % 24);
//      let m = Math.floor(t / 1000 / 60 % 60);
//      let s = Math.floor(t / 1000 % 60);
//      let html = h + " 时" + m + " 分" + s + " 秒";
//  return html
//  }
 const determine=(item,index)=>{
    const data = new Date()
	if(item.m == data.getMonth() + 1 && item.d == data.getDate()){
		return false
	} else if(index==1 && data.getHours() > 17){
		return false
	} else {
		return true
	}
 }
 
 const Jump = (item,index) => {
 	const url = '/pages/table_item/table_item?date=' + item.date + '&restaurantSerials=' + restaurantSerials.value +'&endTime=' +endTime.value
	const data = new Date()
	if(item.m == data.getMonth() + 1 && item.d == data.getDate()){
		return false
	} else if(index == data.getHours() > 17){
		return false
	}
	if(index == 0){
	  return
	}
 	return url
 }
 </script>
 
 <style scoped lang="scss">
	 .end{
		 color: red;
	 }
 .container{
   padding-bottom: 7rpx;
   .img {
     width: 100%;
     height: 280rpx;
 }
 .bg-set {
     position: fixed;
     width: 100%;
     height: 100%;
     top: 0;
     left: 0;
     background-color: #f1f1f1;
     z-index: -1;
 }
 .content {
     display: flex;
     align-items: center;
     .time {
         display: flex;
         flex-direction: column;
         justify-content: center;
         align-items: center;
         width: 250rpx;
         height: 155rpx;
         border-radius: 24rpx;
         margin-right: 20rpx;
         box-sizing: border-box;
     //     color: #007aff;
     //    border: 2rpx solid #007aff;
 background-color:#007aff ;
 color: #fff;
         .item {
             display: flex;
         }
     }
 }
 .title{
     display: flex;
     align-items: center;
     width: 100%;
     background-color: #fff;
     .line{
         width: 13rpx;
         height: 70rpx;
         background-color: #007aff;
         border-radius: 50rpx;
         margin-left: 10rpx;
     }
     .txt{
         font-size: 35rpx;
         font-weight: 700;
         margin-left: 20rpx;
     }
 }
 }
 
 </style>